﻿Public Class frmMain

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Close()
    End Sub

    Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
        dlgBuka.Title = "Select mp3 file ..."
        dlgBuka.FileName = ""
        dlgBuka.ShowDialog()
    End Sub

    Private Sub cmdPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPlay.Click
        If (cmdPlay.Text = "Play") Then
            media.Ctlcontrols.play()
            cmdPlay.Text = "Pause"
        ElseIf (cmdPlay.Text = "Pause") Then
            media.Ctlcontrols.pause()
            cmdPlay.Text = "Play"
        End If

    End Sub

    Private Sub dlgBuka_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles dlgBuka.FileOk
        media.URL = dlgBuka.FileName.ToString
    End Sub

    Private Sub tmrControl_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrControl.Tick
        If (media.playState = WMPLib.WMPPlayState.wmppsPlaying) Then
            trek.SetRange(0, Math.Floor(media.currentMedia.duration))
            trek.Value = Math.Floor(media.Ctlcontrols.currentPosition)
            cmdPlay.Text = "Pause"
            trek.Enabled = True
        ElseIf (media.playState = WMPLib.WMPPlayState.wmppsStopped) Then
            cmdPlay.Text = "Play"
            trek.Enabled = False
        End If

    End Sub

    Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
        media.Ctlcontrols.stop()
        cmdPlay.Text = "Play"

    End Sub

    Private Sub trek_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trek.Scroll
        media.Ctlcontrols.currentPosition = trek.Value
    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        media.Ctlcontrols.stop()
        dlgBuka.Title = "Select mp3 file ..."
        dlgBuka.FileName = ""
        dlgBuka.ShowDialog()
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        frmAbout.Show()
    End Sub
End Class
